package com.example.todolist.service;

import com.example.todolist.mapper.PlanTaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PlanTaskService {
    @Autowired
    private PlanTaskMapper planTaskMapper;
    @Autowired
    private TaskEachDayService taskEachDayService;

    public Integer checkForPlanTask(Integer userId, Integer planTaskId) {
        Integer doneTime = planTaskMapper.getDone(userId,planTaskId)+1;
        Integer total = planTaskMapper.getTotal(userId,planTaskId);
        if(doneTime<total) {
            planTaskMapper.checkForPlanTask(userId, planTaskId, doneTime);
            taskEachDayService.updateTaskEachDay(userId);
            return 1;
        }
        else
        {
            planTaskMapper.deletePlanTask(userId,planTaskId);
            return 0;
        }
    }
}
